import java.util.Scanner;
import java.util.Stack;

/**
 * Created with IDEA
 * author:ju bai
 * Date:2021/4/22
 * Time:9:35
 **/
public class Main2 {
    /**
     * 每日一题-进制转换
     *
     * @param args
     */
    public static void main1(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        change(a, b);
    }

    public static void change(int a, int b) {
        Stack<Character> s = new Stack<>();
        char[] t = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
        if (a > 0) {
            while (a > 0) {
                s.push(t[a % b]);
                a = a / b;
            }
        } else {
            a = Math.abs(a);
            while (a > 0) {
                s.push(t[a % b]);
                a = a / b;
            }
            s.push('-');
        }
        while (!s.isEmpty()) {
            System.out.print(s.pop());
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();
        int n = sc.nextInt();

        StringBuffer s = new StringBuffer();
        String table = "0123456789ABCDEF";
        boolean flg = false;

        if (m < 0) {
            m = -m;
            flg = true;//标记负号
        }
        while (m != 0) {
            s.append(table.charAt(m % n));
            m = m / n;
        }
        if (flg == true) {//说明是负数，需要拼接一个负号
            s.append("-");
        }
        s.reverse();//逆置
        System.out.println(s);
    }
}
